home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / vcrdub / vidbjcts.c < prev   
Encoding:
C/C++ Source or Header  |  1993-06-15  |  12.9 KB  |  571 lines

  1. /*
  2.  * Copyright (c) 1990, 1991, 1992 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/collab/vcrDub/RCS/videoObjects.c,v 0.15 92/11/17 14:42:10 drapeau Exp $ */
  25. /* $Log:    videoObjects.c,v $
  26.  * Revision 0.15  92/11/17  14:42:10  drapeau
  27.  * Corrected errors in the configuration of several players, especially the
  28.  * Pioneer4200 player.
  29.  * 
  30.  * Revision 0.14  92/09/04  17:15:09  drapeau
  31.  * Modified ConvertToTime() and ConvertToAddress() to eliminate calculations
  32.  * based on NTSC-specific frame rates.  The calculations now use the defined
  33.  * constant "FrameRate", which can be set at compile time.
  34.  * Also, minor reformatting of the code to comply with coding standards.
  35.  * Also, removed offset of 25 frames in DubThisEdit(); this offset should
  36.  * really be done in the specific device driver, as frame drift will vary from
  37.  * device to device.
  38.  * Also, commented DubThisEdit() to better explain the dubbing process between
  39.  * source and edit decks, and replaced NTSC-specific references with the
  40.  * defined constant "FrameRate".
  41.  * In main(), used xv_set_rect() to set location and placement of the dub
  42.  * setup window, instead of using the less reliable "XV_X" and "XV_Y"
  43.  * attributes.
  44.  * 
  45.  * Revision 1.14  92/09/03  10:25:12  drapeau
  46.  * Changed communications settings for the NEC driver configuration.
  47.  * 
  48.  * Revision 1.13  92/09/02  17:14:04  drapeau
  49.  * Modified device-specific Config structs to reflect the addition of a
  50.  * new field, "flowControl".
  51.  * 
  52.  * Revision 1.12  92/09/01  16:58:56  drapeau
  53.  * A couple of changes:
  54.  * * Updated copyright notice.
  55.  * * Updated default Config structures to reflect new methods added to the
  56.  *   VideoObject.
  57.  * * Cosmetic changes to make code easier to read.
  58.  * * Added function prototypes for better ANSI compliance.
  59.  * 
  60.  * Revision 1.11  92/07/30  15:15:57  drapeau
  61.  * Improved method for setting asynchronous read function.  The previous
  62.  * version, although designed to be independent of any window system or
  63.  * programming toolkit, was still too reliant on the XView toolkit.  This
  64.  * error no longer exists.
  65.  * Also, minor change to PrintDiagnostics() function; it no longer
  66.  * explicitly terminates with a "\n"; the caller must decide that a
  67.  * "\n" is wanted at the end of the string.
  68.  * 
  69.  * Revision 1.10  92/06/16  23:49:15  drapeau
  70.  * Made a number of changes:
  71.  * * Added support for the Sony CVD1000 (aka "Vdeck") device.
  72.  * * Added 'SetAsynchReadFunction' so as to allow the use of generic toolkit
  73.  *   notify functions for file reads.  This is the first step toward making
  74.  *   the VideoObject toolkit-neutral.
  75.  * 
  76.  * Revision 1.0  91/11/15  17:38:28  collab
  77.  * Initial revision
  78.  * 
  79.  * Revision 0.18  91/09/29  16:12:47  lim
  80.  * Put in all drivers.
  81.  * Added DisplayChoice.
  82.  * 
  83.  * Revision 0.17  91/09/24  22:01:29  lim
  84.  * 1. Used relative filename for driver header file.
  85.  * 
  86.  * Revision 0.16  91/08/24  18:00:57  lim
  87.  * Implemented PrintDiagnostics.
  88.  * 
  89.  * Revision 0.15  91/08/23  17:24:48  lim
  90.  * Included NECDriver.h
  91.  * Clear Marker has been removed as one of the video
  92.  * object functions.
  93.  * 
  94.  * Revision 0.14  91/08/21  10:52:54  lim
  95.  * Added second parameter to DevInit(serialPort).
  96.  * 
  97.  * Revision 0.13  91/08/17  20:45:50  lim
  98.  * 1. Configuration no longer has field for 'interruptibleSegmentPlay'.
  99.  * 2. NECInterrupt becomes NECClearMarker.
  100.  * 
  101.  * Revision 0.12  91/08/15  13:04:51  lim
  102.  * *** empty log message ***
  103.  * 
  104.  * Revision 0.11  91/08/09  11:05:29  lim
  105.  * Moved 'NECDriver.h' from 'vcrEdit.h'
  106.  * 
  107.  * Revision 0.10  91/08/08  17:32:34  lim
  108.  * Initial revision.
  109.  * 
  110.  * Revision 0.11  91/08/07  13:33:39  lim
  111.  * 1. DevInit() now returns pointer to VideoObject.
  112.  * 2. Added instance pointer, "theObject" to all public function calls.
  113.  * 3. DisplayError() is added so that device drivers can call it to 
  114.  * display error messages.
  115.  * 
  116.  * Revision 0.10  91/08/02  12:45:00  lim
  117.  * Initial revision.
  118.  *  */
  119.  
  120. /* WRITING NEW APPLICATION...
  121.  * 1. Replace the header file below with the header file for your own application.
  122.  */
  123.  
  124. #include "vcrDub.h"
  125. #include <Pioneer4200Driver.h>
  126. #include <PanasonicOptDriver.h>
  127. #include <Pioneer6000Driver.h>
  128. #include <Sony1550Driver.h>
  129. #include <NECDriver.h>
  130. #include <CVD1000Driver.h>
  131.  
  132. /* ADDING NEW DRIVERS...
  133.  * 1. Add name of player to the array below.
  134.  * 2. Increment 'numDevices'.
  135.  */
  136.  
  137. char allDevices[MaxDevices][MaxNameLength]= 
  138. {
  139.   "Pioneer4200",
  140.   "Pioneer6000",
  141.   "Panasonic2026",
  142.   "Sony1550",
  143.   "NEC",
  144.   "CVD1000"
  145.   }
  146. ;
  147. int numDevices = 6;
  148.  
  149.  
  150. /* INCLUDE VIDEO OBJECTS HERE */
  151.  
  152.  
  153. /* Video Object for Pioneer4200 */
  154.  
  155. static Config Pioneer4200Config = 
  156. {
  157.   "Pioneer4200",
  158.   "/dev/ttya",
  159.   4800,
  160.   13,
  161.   8,
  162.   NoParity,
  163.   No,
  164.   No,
  165.   120,
  166.   -1
  167.   }
  168. ;
  169.  
  170. static VideoObject Pioneer4200Obj = 
  171. {
  172.   &Pioneer4200Config,
  173.   Pioneer4200Play,
  174.   Pioneer4200PlayFromTo,
  175.   Pioneer4200FastForward,
  176.   Pioneer4200Reverse,
  177.   Pioneer4200CalcSpeed,
  178.   Pioneer4200PlayAtSpeedDir,
  179.   Pioneer4200Step,
  180.   Pioneer4200Still,
  181.   Pioneer4200Stop,
  182.   Pioneer4200SetDefaults,
  183.   Pioneer4200SetAudio,
  184.   Pioneer4200SetVideo,
  185.   Pioneer4200SetAddMode,
  186.   Pioneer4200SetAddressDisplay,
  187.   Pioneer4200Eject,
  188.   Pioneer4200Power,
  189.   Pioneer4200QueryFrame,
  190.   Pioneer4200QueryChapter,
  191.   Pioneer4200QueryAudio,
  192.   Pioneer4200QueryVideo,
  193.   Pioneer4200QueryMedium,
  194.   Pioneer4200QueryStatus, 
  195.   Pioneer4200Ping,
  196.   NULL,
  197.   NULL
  198.   }
  199. ;
  200.  
  201. /* Video Object for CVD1000 */
  202.  
  203. static Config CVD1000Config = 
  204. {
  205.   "CVD1000",
  206.   "/dev/ttya",
  207.   9600,
  208.   -1,
  209.   8,
  210.   NoParity,
  211.   No,
  212.   No,
  213.   60,
  214.   -1
  215.   }
  216. ;
  217.  
  218. static VideoObject CVD1000Obj = 
  219. {
  220.   &CVD1000Config,
  221.   CVD1000Play,
  222.   CVD1000PlayFromTo,
  223.   CVD1000FastForward,
  224.   CVD1000Reverse,
  225.   CVD1000CalcSpeed,
  226.   CVD1000PlayAtSpeedDir,
  227.   CVD1000Step,
  228.   CVD1000Still,
  229.   CVD1000Stop,
  230.   CVD1000SetDefaults,
  231.   CVD1000SetAudio,
  232.   CVD1000SetVideo,
  233.   CVD1000SetAddMode,
  234.   CVD1000SetAddressDisplay,
  235.   CVD1000Eject,
  236.   CVD1000Power,
  237.   CVD1000QueryFrame,
  238.   CVD1000QueryChapter,
  239.   CVD1000QueryAudio,
  240.   CVD1000QueryVideo,
  241.   CVD1000QueryMedium,
  242.   CVD1000QueryStatus, 
  243.   CVD1000Ping,
  244.   CVD1000Record,
  245.   CVD1000RecordFromTo
  246.   }
  247. ;
  248.  
  249. /* Video Object for PanasonicOpticalDiskPlayer */
  250.  
  251. static Config PanasonicOptConfig = 
  252. {
  253.   "Panasonic2026",
  254.   "/dev/ttyb",
  255.   1200,
  256.   13,
  257.   8,
  258.   Even,
  259.   Yes,
  260.   Yes,
  261.   300, 
  262.   -1
  263.   }
  264. ;
  265.  
  266. static VideoObject PanasonicOptObj = 
  267. {
  268.   &PanasonicOptConfig,
  269.   PanasonicOptPlay,
  270.   PanasonicOptPlayFromTo,
  271.   PanasonicOptFastForward,
  272.   PanasonicOptReverse,
  273.   PanasonicOptCalcSpeed,
  274.   PanasonicOptPlayAtSpeedDir,
  275.   PanasonicOptStep,
  276.   PanasonicOptStill,
  277.   PanasonicOptStop,                            
  278.   PanasonicOptSetDefaults,                        
  279.   PanasonicOptSetAudio,                        
  280.   PanasonicOptSetVideo,
  281.   NULL,
  282.   PanasonicOptSetAddressDisplay,
  283.   PanasonicOptEject,
  284.   NULL,
  285.   PanasonicOptQueryFrame,
  286.   NULL,
  287.   NULL,
  288.   NULL,
  289.   PanasonicOptQueryMedium,
  290.   PanasonicOptQueryStatus,
  291.   PanasonicOptPing,
  292.   NULL,
  293.   NULL
  294.   }
  295. ;
  296.  
  297. /* Video Object for Pioneer6000 */
  298.  
  299. static Config Pioneer6000Config = 
  300. {
  301.   "Pioneer6000",
  302.   "/dev/ttyb",
  303.   1200,
  304.   13,
  305.   8,
  306.   Even,
  307.   Yes,
  308.   Yes,
  309.   90,
  310.   -1
  311.   }
  312. ;
  313.  
  314. static VideoObject Pioneer6000Obj = 
  315. {
  316.   &Pioneer6000Config,
  317.   Pioneer6000Play,
  318.   Pioneer6000PlayFromTo,
  319.   Pioneer6000FastForward,
  320.   Pioneer6000Reverse,
  321.   Pioneer6000CalcSpeed,
  322.   Pioneer6000PlayAtSpeedDir,
  323.   Pioneer6000Step,
  324.   Pioneer6000Still,
  325.   Pioneer6000Stop,                            
  326.   Pioneer6000SetDefaults,                        
  327.   Pioneer6000SetAudio,                        
  328.   Pioneer6000SetVideo,
  329.   NULL,
  330.   Pioneer6000SetAddressDisplay,
  331.   Pioneer6000Eject,
  332.   NULL,
  333.   Pioneer6000QueryFrame,
  334.   NULL,
  335.   NULL,
  336.   NULL,
  337.   NULL,
  338.   Pioneer6000QueryStatus,
  339.   Pioneer6000Ping,
  340.   NULL,
  341.   NULL
  342.   }
  343. ;
  344.  
  345. /* Video Object for Sony1550 */
  346.  
  347. static Config Sony1550Config = 
  348. {
  349.   "Sony1550",
  350.   "/dev/ttyb",
  351.   2400,
  352.   -1,
  353.   8,
  354.   Even,
  355.   Yes,
  356.   Yes,
  357.   90,
  358.   -1
  359.   }
  360. ;
  361.  
  362. static VideoObject Sony1550Obj = 
  363. {
  364.   &Sony1550Config,
  365.   Sony1550Play,
  366.   Sony1550PlayFromTo,
  367.   Sony1550FastForward,
  368.   Sony1550Reverse,
  369.   Sony1550CalcSpeed,
  370.   Sony1550PlayAtSpeedDir,
  371.   Sony1550Step,
  372.   Sony1550Still,
  373.   Sony1550Stop,                            
  374.   Sony1550SetDefaults,                        
  375.   Sony1550SetAudio,                        
  376.   Sony1550SetVideo,
  377.   Sony1550SetAddMode,
  378.   Sony1550SetAddressDisplay,
  379.   Sony1550Eject,
  380.   NULL,
  381.   Sony1550QueryFrame,
  382.   Sony1550QueryChapter,
  383.   NULL,
  384.   NULL,
  385.   Sony1550QueryMedium,
  386.   Sony1550QueryStatus,
  387.   Sony1550Ping,
  388.   NULL,
  389.   NULL
  390.   }
  391. ;
  392.  
  393.  
  394. /* Video Object for NEC PC VCR */
  395.  
  396. static Config NECConfig = 
  397. {
  398.   "NEC",
  399.   "/dev/ttya",
  400.   1200,
  401.   13,
  402.   8,
  403.   NoParity,
  404.   No,
  405.   No,
  406.   270,
  407.   -1
  408.   }
  409. ;
  410.  
  411. static VideoObject NECObj = 
  412. {
  413.   &NECConfig,
  414.   NECPlay,
  415.   NECPlayFromTo,
  416.   NECFastForward,
  417.   NECReverse,
  418.   NECCalcSpeed,
  419.   NECPlayAtSpeedDir,
  420.   NECStep,
  421.   NECStill,
  422.   NECStop,
  423.   NECSetDefaults,
  424.   NECSetAudio,
  425.   NECSetVideo,
  426.   NECSetAddressingMode,
  427.   NULL,
  428.   NECEject,
  429.   NECPower,
  430.   NECQueryFrame,
  431.   NULL,
  432.   NECQueryAudio,
  433.   NECQueryVideo,
  434.   NECReadHeader,
  435.   NECQueryStatus,
  436.   NECPing,
  437.   NECRecord,
  438.   NECRecordFromTo
  439.   }
  440. ;
  441.  
  442.  
  443. /* DevInit builds the video object for the appropriate ...
  444.  * ... device and sets up the serial line.  It returns the ...
  445.  * ... pointer to the video object.
  446.  */
  447.  
  448. VideoObject*
  449.   DevInit(char*    deviceName,
  450.       char* serialPort)
  451. {
  452.   VideoObject* myVideo;
  453.   
  454.   /* ADDING NEW DRIVERS
  455.      ... Add statements for new device here, as another else-if statement */
  456.   
  457.   if (strcmp(deviceName, "Pioneer4200") == 0)                /* Set the video object to the appropriate variable */
  458.     myVideo = BuildVideoObject(&Pioneer4200Obj);
  459.   else if (strcmp(deviceName, "Sony1550") == 0)
  460.     myVideo = BuildVideoObject(&Sony1550Obj);
  461.   else if (strcmp(deviceName, "Panasonic2026") == 0)
  462.     myVideo = BuildVideoObject(&PanasonicOptObj);
  463.   else if (strcmp(deviceName, "Pioneer6000") == 0)
  464.     myVideo = BuildVideoObject(&Pioneer6000Obj);
  465.   else if (strcmp(deviceName, "NEC") == 0)
  466.     myVideo = BuildVideoObject(&NECObj);                
  467.   else if (strcmp(deviceName, "CVD1000") == 0)
  468.     myVideo = BuildVideoObject(&CVD1000Obj);                
  469.   
  470.   if (PlayerVerified(myVideo, serialPort) != -1)            /* Sets up serial line for communicating with the device */
  471.     if (SetSerialLine(myVideo->DevConfig, serialPort))
  472.       return myVideo;
  473.     else
  474.       return NULL;
  475.   else
  476.     return NULL;
  477. }                                    /* end function DevInit */
  478.  
  479.  
  480.  
  481. /* WRITING NEW APPLICATIONS... 
  482.  * Optional : Replace the code within DisplayError() if a different 
  483.  * error notification function is desired.
  484.  *
  485.  * DO NOT remove the function DisplayError().
  486.  * 
  487.  * DisplayError() is useful in displaying errors other than those dealing
  488.  * with the device.
  489.  */
  490.  
  491. /* WRITING NEW DRIVERS...
  492.  * IMPORTANT : 
  493.  * Video drivers should be written such that any detectable error
  494.  * is decoded into English and placed into at most 2 strings. Then the
  495.  * driver is responsible for calling DisplayError() which displays the
  496.  * errors appropriately to the user.
  497.  */
  498.  
  499. /* DisplayError takes 2 strings that explain the error condition encountered.
  500.  */
  501. void
  502. DisplayError(char* errorMsg1,
  503.          char* errorMsg2)
  504. {
  505.   notice_prompt(vcrDub_window1->window1, NULL,
  506.         NOTICE_MESSAGE_STRINGS,
  507.         errorMsg1,
  508.         errorMsg2,
  509.         NULL,
  510.         NOTICE_BUTTON,    "OK", 100,
  511.         NULL);
  512. }
  513.  
  514.  
  515. /* Display choice message */
  516. int
  517. DisplayChoice(char* msg1,
  518.           char* msg2,
  519.           char* r1,
  520.           char* r2)
  521. {
  522.   int result = notice_prompt(vcrDub_window1->window1, NULL,
  523.                  NOTICE_MESSAGE_STRINGS,
  524.                  msg1, msg2,
  525.                  NULL,
  526.                  NOTICE_BUTTON_YES, r1,
  527.                  NOTICE_BUTTON_NO, r2, 
  528.                  NULL);
  529.   return result;
  530.   
  531. }
  532.  
  533.  
  534. void
  535. PrintDiagnostics(char* msg)
  536. {
  537.   if (diagMode == Yes)
  538.     fprintf(stderr, "%s", msg);
  539. }
  540.  
  541.  
  542. static int (*callbackProc)(int);                    /* Pointer to function called when asynch read is needed */
  543.  
  544.     
  545. Notify_value MyAsyncCallback(Notify_client    client,
  546.                  int        fd)
  547. {
  548.   return((*callbackProc) (fd));
  549. }                                    /* end function MyAsyncCallback */
  550.  
  551.  
  552.  
  553. void 
  554. SetAsynchReadFunction(int    (*callback)(int),
  555.               int    fd,
  556.               int    onOrOff)
  557. {
  558.   /* Code here would use the callback function provided to be
  559.      called when input occurred on the file descriptor of "theObject".
  560.      For XView, the code might be this:
  561.      */
  562.   callbackProc = callback;
  563.   
  564.   if (onOrOff == FeatureOn)
  565.     notify_set_input_func((Notify_client) AppClient, 
  566.               MyAsyncCallback, fd);
  567.   else
  568.     notify_set_input_func((Notify_client) AppClient,
  569.               NOTIFY_FUNC_NULL, fd);            /* Turn off automatic read */
  570. }                                    /* end function SetAsynchReadFunction */
  571.